package com.yuan.java.socket;

import com.yuan.java.pack16.SocketPackUtils;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
    @Test
    public void mains() throws Exception {
        String msg = "hello world";
        Socket socket = new Socket("10.1.1.18", 8001);
        PrintWriter pw = new PrintWriter(socket.getOutputStream());
        pw.println(msg);

        BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        pw.flush();

        String line = is.readLine();
        System.out.println(SocketPackUtils.byteArr2HexStrBlank(line.getBytes()));
        pw.close();
        is.close();
        socket.close();
    }
}
